package com.jvtd.demo.im.bean;

import android.content.Context;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.TextUtils;
import android.text.method.LinkMovementMethod;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.jvtd.demo.R;

import io.rong.imkit.model.ProviderTag;
import io.rong.imkit.model.UIMessage;
import io.rong.imkit.widget.provider.IContainerItemProvider.MessageProvider;

@ProviderTag(
        messageContent = MyInformationNotificationMessage.class,
        showPortrait = false,
        showProgress = false,
        showWarning = false,
        centerInHorizontal = true,
        showSummaryWithName = false
)
public class MyInfoNotificationMsgItemProvider extends MessageProvider<MyInformationNotificationMessage>
{
  public MyInfoNotificationMsgItemProvider()
  {
  }

  public void bindView(View v, int position, MyInformationNotificationMessage content, UIMessage message)
  {
    MyInfoNotificationMsgItemProvider.ViewHolder viewHolder = (MyInfoNotificationMsgItemProvider.ViewHolder) v.getTag();
    if (content != null && !TextUtils.isEmpty(content.getMessage()))
    {
      viewHolder.contentTextView.setText(content.getMessage());
    }

  }

  public Spannable getContentSummary(MyInformationNotificationMessage data)
  {
    return null;
  }

  public Spannable getContentSummary(Context context, MyInformationNotificationMessage data)
  {
    return data != null && !TextUtils.isEmpty(data.getMessage()) ? new SpannableString(data.getMessage()) : null;
  }

  public void onItemClick(View view, int position, MyInformationNotificationMessage content, UIMessage message)
  {
  }

  public void onItemLongClick(View view, int position, MyInformationNotificationMessage content, UIMessage message)
  {
  }

  public View newView(Context context, ViewGroup group)
  {
    View view = LayoutInflater.from(context).inflate(R.layout.rc_item_information_notification_message, (ViewGroup) null);
    MyInfoNotificationMsgItemProvider.ViewHolder viewHolder = new MyInfoNotificationMsgItemProvider.ViewHolder();
    viewHolder.contentTextView = (TextView) view.findViewById(R.id.rc_msg);
    viewHolder.contentTextView.setMovementMethod(LinkMovementMethod.getInstance());
    view.setTag(viewHolder);
    return view;
  }

  private static class ViewHolder
  {
    TextView contentTextView;

    private ViewHolder()
    {
    }
  }
}